home *** CD-ROM | disk | FTP | other *** search
/ Amiga Game-Power / Amiga Game-Power.iso / pd mix ii / access / hddriver / support / interleave.c < prev    next >
C/C++ Source or Header  |  1994-05-20  |  2KB  |  80 lines

  1. #include <stdio.h>
  2. #include "hd.h"
  3.  
  4. APTR IntuitionBase;
  5. extern APTR OpenLibrary ();
  6.  
  7. char buf[512];
  8.  
  9. main ()
  10. {
  11.     int i;
  12.     long sec1,sec2, micro1,micro2;
  13.     struct posn posn;
  14.     int loop;
  15.  
  16.     IntuitionBase = OpenLibrary ( "intuition.library" , 0L );
  17.     if ( IntuitionBase == NULL ) {
  18.         printf ( "Failed to open intuition.library\n" );
  19.         exit ( 1 );
  20.     }
  21.     if ( wd_open () == 0 ) {
  22.         posn.cylinder = 10;
  23.         posn.surface = 0;
  24.         for ( i = 0; i < first.sectors; i++ ) {
  25.             printf ( "Trying interleave %d\n" , i );
  26.             fflush ( stdout );
  27.             new_interleave ( i , first.sectors );
  28.             posn.sector = 0;
  29.             posn.block = posn.sector + ( posn.surface * first.sectors )
  30.                 + ( posn.cylinder * first.sectors * first.heads );
  31.             wd_format_track ( &posn );
  32.             CurrentTime ( &sec1 , µ1 );
  33.             for ( loop = 0; loop < 20; loop++ ) {
  34.                 for ( posn.sector = 0; posn.sector < first.sectors; posn.sector++ ) {
  35.                     posn.block = posn.sector
  36.                         + ( posn.surface * first.sectors )
  37.                         + ( posn.cylinder * first.sectors * first.heads );
  38.                     read_sector ( &posn , buf );
  39.                 }
  40.             }
  41.             CurrentTime ( &sec2 , µ2 );
  42.             sec2 -= sec1;
  43.             micro2 -= micro1;
  44.             if ( micro2 < 0 ) {
  45.                 micro2 += 1000000;
  46.                 sec2--;
  47.             }
  48.             printf ( "difference %ld sec, %ld micro\n" , sec2 , micro2 );
  49.         }
  50.         wd_close ();
  51.     }
  52.     else
  53.         printf ( "wd_reset() failed\n" );
  54.     CloseLibrary ( IntuitionBase );
  55. }
  56.  
  57.  
  58. new_interleave ( interleave )
  59. int interleave;
  60. {
  61.     int i;
  62.     int j;
  63.  
  64.     for ( i = 0; i < first.sectors; i++ )
  65.         first.interleave[i*2+1] = first.sectors;    /* mark as free */
  66.     j = 0;
  67.     for ( i = 0; i < first.sectors; i++ ) {
  68.         while ( first.interleave[j*2+1] != first.sectors ) {
  69.             j++;
  70.             while ( j >= first.sectors ) j -= first.sectors;
  71.         }
  72.         first.interleave[j*2+1] = i;
  73.         j += interleave;
  74.         while ( j >= first.sectors ) j -= first.sectors;
  75.     }
  76.     for ( i = 0; i < first.sectors; i++ )
  77.         printf ( "%d " , first.interleave[i*2+1] );
  78.     printf ( "\n" );
  79. }
  80.